Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

png-async

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

png-async

A simple and non-blocking PNG encoder / decoder.

  • 0.9.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is png-async?

The png-async npm package is a library for reading and writing PNG images asynchronously. It provides a simple API for manipulating PNG images, making it suitable for applications that require image processing without blocking the main thread.

What are png-async's main functionalities?

Reading PNG files

This feature allows you to read PNG files asynchronously. The code sample demonstrates how to read a PNG file from the filesystem, parse it, and log its width, height, and pixel data.

const fs = require('fs');
const PNG = require('png-async');

fs.createReadStream('input.png')
  .pipe(new PNG())
  .on('parsed', function() {
    console.log('Width:', this.width);
    console.log('Height:', this.height);
    console.log('Data:', this.data);
  });

Writing PNG files

This feature allows you to write PNG files asynchronously. The code sample demonstrates how to create a new PNG image, manipulate its pixel data to fill it with red color, and save it to the filesystem.

const fs = require('fs');
const PNG = require('png-async');

const png = new PNG({ width: 100, height: 100 });

for (let y = 0; y < png.height; y++) {
  for (let x = 0; x < png.width; x++) {
    const idx = (png.width * y + x) << 2;
    png.data[idx] = 255; // Red
    png.data[idx + 1] = 0; // Green
    png.data[idx + 2] = 0; // Blue
    png.data[idx + 3] = 255; // Alpha
  }
}

png.pack().pipe(fs.createWriteStream('output.png'));

Transforming PNG images

This feature allows you to transform PNG images asynchronously. The code sample demonstrates how to read a PNG file, invert its colors, and save the transformed image to the filesystem.

const fs = require('fs');
const PNG = require('png-async');

fs.createReadStream('input.png')
  .pipe(new PNG())
  .on('parsed', function() {
    for (let y = 0; y < this.height; y++) {
      for (let x = 0; x < this.width; x++) {
        const idx = (this.width * y + x) << 2;
        // Invert colors
        this.data[idx] = 255 - this.data[idx];
        this.data[idx + 1] = 255 - this.data[idx + 1];
        this.data[idx + 2] = 255 - this.data[idx + 2];
      }
    }
    this.pack().pipe(fs.createWriteStream('output.png'));
  });

Other packages similar to png-async

Keywords

FAQs

Package last updated on 04 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc